const App = {
  mixins: [Query], //配置文件，路径/utils/mixins.js
  data() {
    return {
      page: {
        value1: '',
        PageNumber: 1, //页码
        RowAmount: 20,
        Condition: window.btoa(unescape(encodeURIComponent("%%,%%"))),
      },
      points:0,
    };
  },
  mounted() {
    $.ajax({
      headers: requestHeaders(),
      url: `${mh}/generalBusiness/generalQueryByTableName`,
      method: "post",
      data: {
        Data: 'complaints_points_config',
        Condition: `Row_Status='0' ORDER BY Create_Datetime DESC LIMIT 1`
      },
      success: (res) => {
        if (res.length == 1) {
          this.points = res[0].Points
        } else {
          this.points = 0
        }
      },
      complete: (XMLHttpRequest) => {
        requestPretreatment(XMLHttpRequest)
      },
    });
  },
  methods: {
    handleNodeClick(data, node) {
      this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%" + data.category_id + "%")));
      this.postgetList(this.page);
    },
    handlePoins(row) {
      this.$confirm('该操作将发放'+this.points+'积分,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableName`,
          method: "post",
          data: {
            Data: 'personal_information',
            Condition: `Contact_Phone='${row.Creater_SerialNumber}'`,
          },
          success: (data) => {
            if (data.length == 1) {
              const ID_Card_Number = data[0].ID_Card_Number;
              $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
                method: "post",
                data: {
                  Data: 'personal_points_account',
                  Condition: `ID_Card_Number='${ID_Card_Number}' AND Points_Type='0'`,
                },
                success: (data) => {
                  console.log(data);
                  let personal_points_change_log = [];
                  let lJSONObject_DataSet = {
                    Add:{
                      complaints_points_log:[{
                        complaint_id:row.complaint_id,
                        Points:this.points,
                        Points_Type:'0',
                      }],
                    },
                  };
                  if (data.length == 1) {
                    data[0].Remain_Points = accAdd(this.points, data[0].Remain_Points);
                    data[0].Total_Points = accAdd(this.points, data[0].Total_Points);
                    lJSONObject_DataSet.Modify = {
                      personal_points_account: data
                    }
                    personal_points_change_log = [{
                      ID_Card_Number,
                      Points_Title:'事件增加积分',
                      Points_Type:'0',
                      Object_SerialNumber:row.complaint_id,
                      Change_Points:this.points,
                      Remain_Points: data[0].Remain_Points,
                      Notes:'事件增加积分'
                    }]
                  } else {
                    lJSONObject_DataSet.Add.personal_points_account = [{
                      ID_Card_Number,
                      Points_Type:'0',
                      Total_Points:this.points,
                      Remain_Points:this.points,
                      Sales_Points:'0'
                    }]
                    personal_points_change_log = [{
                      ID_Card_Number,
                      Points_Title:'事件增加积分',
                      Points_Type:'0',
                      Object_SerialNumber:row.complaint_id,
                      Change_Points:this.points,
                      Remain_Points: this.points,
                      Notes:'事件增加积分'
                    }]
                  }
                  lJSONObject_DataSet.Add.personal_points_change_log = personal_points_change_log;
                  let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                  lJSONObject_DataSet['Add']['base_operation_log'] = [{
                    Operation_Type: '0',
                    Operation_Path: this.relativePath,
                    Operation_Main,
                    Operation_Interface: "generalSaveByRequestBody",
                    Operation_IP: getIpAddress()
                  }]
                  submitSave(lJSONObject_DataSet, (res) => {
                    if (res.Status == 'success') {
                      this.postgetList(this.page);
                    }
                  })
                },
                complete: (XMLHttpRequest) => {
                  requestPretreatment(XMLHttpRequest)
                },
              });
            } else {
              this.$message({
                type: 'success',
                message: '删除失败'
            });
            }
          },
          complete: (XMLHttpRequest) => {
            requestPretreatment(XMLHttpRequest)
          },
        });
      }).catch(() => { });
    }
  },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
